package com.spyx.acl.service.impl;

import com.atyx.spyx.model.acl.Role;
import com.atyx.spyx.vo.acl.RoleQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spyx.acl.mapper.RoleMapper;
import com.spyx.acl.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    //调取mapper层
    //private RoleMapper roleMapper;


    @Override
    public List<Role> getAllRoles() {

        return baseMapper.selectList(null);
    }

    @Override
    public IPage<Role> selectRoleList(Page page, RoleQueryVo roleQueryVo) {
        //模糊查询条件
        String roleName = roleQueryVo.getRoleName();

        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(roleName)){   //判断角色name非空
            wrapper.like(Role::getRoleName,roleName); // rolename like 'xx'
        }

        IPage rs = baseMapper.selectPage(page, wrapper);
        return rs;
    }
}
